package com.ruoyi.project.pay.facai;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



public class SignUtil {
	private static final Logger log = LoggerFactory
			.getLogger(SignUtil.class);
	public static Map<String, String> getSign(List<Map<String, String>>list,String key) {
        StringBuffer sb = new StringBuffer();
        Map<String, String> mp=new HashMap<String, String>();
        for(Map<String, String> m:list){
            for (Map.Entry<String, String> entry : m.entrySet()) {
                if (null != entry.getValue() && !"".equals(entry.getValue())
                        && "" != entry.getValue() && !"sign".equals(entry.getKey())) {
                    sb.append(entry.getKey() + "=" + entry.getValue() + "&");
                }
            }
        }
        sb.append("key=" + key);
        String result = sb.toString();
        result = Md5Util.MD5Encode(result).toUpperCase();
        mp.put("sign", result);
        return mp;
    }
	
	public static Map<String, String> getSign(Map<String, String> map,String key) {
        StringBuffer sb = new StringBuffer();
        for (Map.Entry<String, String> entry : map.entrySet()) {
            if (null != entry.getValue() && !"".equals(entry.getValue())
                    && "" != entry.getValue() && !"sign".equals(entry.getKey())) {
                sb.append(entry.getKey() + "=" + entry.getValue() + "&");
            }
        }
        sb.append("key=" + key);
        String result = sb.toString();
        log.info("getSign result {}",result);
        result = Md5Util.MD5Encode(result).toUpperCase();
        map.put("sign", result);
        return map;
    }
	public static Map<String, Object> getSignObject(Map<String, Object> map,String key) {
        StringBuffer sb = new StringBuffer();
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            if (null != entry.getValue() && !"".equals(entry.getValue())
                    && "" != entry.getValue() && !"sign".equals(entry.getKey())) {
                sb.append(entry.getKey() + "=" + entry.getValue() + "&");
            }
        }
        sb.append("key=" + key);
        String result = sb.toString();
        result = Md5Util.MD5Encode(result).toUpperCase();
        map.put("sign", result);
        return map;
    }
}
